package com.pci.netty.client.channel;

import com.pci.netty.business.IHandler;
import com.pci.netty.business.impl.HeartbeatHandler;
import com.pci.netty.business.impl.RestartHandler;
import com.pci.netty.client.BootNeetyClient;
import com.pci.netty.handler.CommadHandler;
import com.pci.netty.handler.KeepaliveHandler;
import com.pci.netty.handler.Line18ControlDecode;
import io.netty.channel.Channel;
import io.netty.channel.ChannelInitializer;
import io.netty.channel.ChannelPipeline;
import io.netty.handler.codec.LengthFieldPrepender;

import java.util.HashMap;
import java.util.Map;

/**
 * 通道初始化
 *
 * @param <SocketChannel>
 */
public class ClientNettyChannelInitializer<SocketChannel> extends ChannelInitializer<Channel> {
    private BootNeetyClient client;

    public ClientNettyChannelInitializer(BootNeetyClient client) {
        this.client = client;
    }

    @Override
    protected void initChannel(Channel ch) throws Exception {
        ChannelPipeline pipeline = ch.pipeline();

        pipeline.addLast(new LengthFieldPrepender(4, false));
        pipeline.addLast(new Line18ControlDecode(Integer.MAX_VALUE, 0, 4));
        pipeline.addLast(new KeepaliveHandler(client));
    }
}

